function rootpoly=rootpol(lagpol); 
%function rootpoly=rootpol(lagpol); 
% Find the roots of a lag polynomial  
% Polynomial a(0)-a(1)L-....-a(d)L^d 
% Re-scale the first coefficient 
% Notice that roots in MATLAB operates on 
% a(d)L^d+.......+a(d)L+a(0) 
% HERE all roots should be OUTSIDE the unit circle for both 
% Invertibility of an MA(d) 
% Fundamentalness of the error in an AR(d)
% FOR CONSISTENCY NOTATION IN HAMILTON
% IF AR(D) enter as [1 0.8 0.9]  =1-0.8L-0.9L^2 
% IF MA(D) enter as [1 -0.8 -0.9]=1+0.8+0.9L^2
% Can obtain back the lag polynomial for the MA case with invertma.m
firstel=lagpol(1); 
lagpol=lagpol/firstel; 
lagpol=[-1*fliplr(lagpol(2:end)) lagpol(1)]; 
rootpoly=roots(lagpol);
